package comet.measure;

import comet.util.OWL2JungGraph;

import com.hp.hpl.jena.ontology.OntClass;
import com.hp.hpl.jena.ontology.OntModel;
import com.hp.hpl.jena.ontology.OntProperty;
import com.hp.hpl.jena.ontology.OntResource;

import edu.uci.ics.jung.algorithms.shortestpath.DijkstraShortestPath;
import edu.uci.ics.jung.graph.Graph;

public class OntologyIntraDistance {
	
	public static double getDistance(OntModel onto, OntClass source, OntClass target) {
		return getSSM(onto,source,target);
	}
	
	public static double getSSM(OntModel onto, OntClass source, OntClass target) {
		Graph<OntResource, OntProperty> graph = OWL2JungGraph.OWL2JungGraph(onto);
		DijkstraShortestPath<OntResource, OntProperty>  dijkstra = new DijkstraShortestPath<OntResource, OntProperty>(graph);
		double length = 0.0;
		double similarity = 0.0;
		if (dijkstra.getDistance(source, target) != null) {
			length = dijkstra.getDistance(source, target).doubleValue();
			if (length != 0.0)
				similarity = 1/length;
		}
		return similarity;
	}
}
